//
//  MyOrderViewController.m
//  MIDI
//
//  Created by E.M.Game on 15/9/11.
//  Copyright (c) 2015年 QXSX. All rights reserved.
//

#import "MyOrderViewController.h"
#import "AppConfig.h"
#import "MyOrderViewCell.h"
#import "MyOrderPayViewControl.h"
#import "SIAlertView.h"
#import "APIAdress.h"
#import "MyOrderModel.h"
#import "QXNetWorkTool.h"
#import "UIViewController+Create.h"
#import "UIViewController+NavItem.h"
#import <UIKit/UIAlertView.h>
#import "UserDataSingleton.h"
#import "MBProgressHUD+YC.h"
#import "CommFunc.h"
#import "AliPayTool.h"
#import "AccountTool.h"
#import "WXApi.h"
#import "WXPrePayIdModel.h"
#import "WeChatPayTool.h"
#import "OperanViewController.h"
#import "MusicTexbookDetailModel.h"
#import "BuyMusicDetailViewViewController.h"
#import "MJRefresh.h"

@interface MyOrderViewController ()<UITableViewDelegate , UITableViewDataSource,
                                    MyOrderPayViewDeletage, UIAlertViewDelegate ,
                                    QXNetWorkToolDelegate>

@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet UIButton *notPayedBtn;
@property (weak, nonatomic) IBOutlet UIButton *payedBtn;
@property (assign , nonatomic) BOOL isPayedStatus;  //当前显示得页面是已付款还是未付款
@property (strong , nonatomic) QXNetWorkTool * netTool;
@property (strong , nonatomic) NSMutableArray * order_Pay;   //已付款订单
@property (strong , nonatomic) NSMutableArray * order_NotPay;
@property (assign , nonatomic) BOOL isInitPayOrder;
@property (assign , nonatomic) BOOL isInitNotPayOrder;
@property (strong , nonatomic) MyOrderModel *selectItemdata;
@property(assign , nonatomic) int payType;
@property (copy , nonatomic) NSString *fileUrl;
@property (assign,nonatomic) int pageNumPayed;
@property (assign,nonatomic) int pageNumNoPaye;

@end

@implementation MyOrderViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.notPayedBtn addTarget:self action:@selector(pressNotPayedBtn:) forControlEvents:UIControlEventTouchUpInside];
    [self.payedBtn addTarget:self action:@selector(pressPayedBtn:) forControlEvents:UIControlEventTouchUpInside];
    self.netTool = [[QXNetWorkTool alloc] init];
    self.netTool.QXNetWorkDelegate = self;
    self.order_Pay = [[NSMutableArray alloc] init];
    self.order_NotPay = [[NSMutableArray alloc] init];
    self.isInitNotPayOrder = NO;
    self.isInitPayOrder = NO;
    self.payType = -1;
    
    self.pageNumPayed = 1;
    self.pageNumNoPaye = 1;
    
    self.tableView.header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)];
    
    self.tableView.footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self configNavigationItem];
    self.isPayedStatus = false;
    [self refreshUI];
    
    [self.order_NotPay removeAllObjects];
    self.pageNumNoPaye = 1;
    
    [self reqOrderList];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

-(void) configNavigationItem
{
    [self.tabBarController configNavigationBarTintColor:UIColorRGBA(0, 0, 0, 1)];
    [self.navigationController.navigationBar setBarTintColor:MIDIColorOfNavigationBar];
    self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
    self.navigationItem.title = @"订单详情";
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],UITextAttributeTextColor, [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0],UITextAttributeTextShadowColor,[UIFont fontWithName:@"Hiragino Sans GB" size:18.0],UITextAttributeFont,nil]];
    
    [self configNavigationBackAction:^{
        
        [self.navigationController popViewControllerAnimated:YES];
    }];
    
    
}

-(void)refreshUI
{
    if(self.isPayedStatus)  //已付款
    {
        [self.notPayedBtn setTitleColor:UIColorRGBA(187,187,187, 1) forState:UIControlStateNormal];
        [self.payedBtn setTitleColor:UIColorRGBA(0, 0, 0, 1) forState:UIControlStateNormal];
        [self.tableView reloadData];
    }
    else //未付款
    {
        [self.notPayedBtn setTitleColor:UIColorRGBA(0,0,0, 1) forState:UIControlStateNormal];
        [self.payedBtn setTitleColor:UIColorRGBA(187, 187, 187, 1) forState:UIControlStateNormal];
        [self.tableView reloadData];
    }
}

#pragma mark     --------- QuxNetTool---------------------------------------
-(void)reqOrderList
{
    UserDataSingleton *userdata = [UserDataSingleton shareInstance];
    NSString * order_state_code = @"0";
    NSString *pagenum;
    if(self.isPayedStatus)
    {
//        if(self.isInitPayOrder && !userdata.isOrderChange)
//            return;
        order_state_code = @"1";
        
        pagenum = [NSString stringWithFormat:@"%d",self.pageNumPayed];
    }
    else
    {
//        if(self.isInitNotPayOrder && !userdata.isOrderChange)
//            return;
        
        order_state_code = @"0";
        
        pagenum = [NSString stringWithFormat:@"%d",self.pageNumNoPaye];
    }
    
    [MBProgressHUD showMessage:@"正在加载" toView:self.view];
    
    [self.netTool GetDataFromServerWithPostMethodandInterfaceName:MyOrderListInterface andParameter:
     @[@{@"user_id":userdata.user_id ,
         @"order_state_code":order_state_code,
         @"nowpage":pagenum,
         @"pagesize":@"10"}] tag:1];
}

#pragma mark 设置上下拉刷新

- (void)loadNewData
{
    if(self.isPayedStatus)
    {
        [self.order_Pay removeAllObjects];
        
        self.pageNumPayed = 1;
    }
    else
    {
        [self.order_NotPay removeAllObjects];
        
        self.pageNumNoPaye = 1;
    }
    
    [self reqOrderList];
    [self.tableView.header endRefreshing];
}

- (void)loadMoreData
{
    if(self.isPayedStatus)
    {
        ++self.pageNumPayed;
    }
    else
    {
        ++self.pageNumNoPaye;
    }
    
    [self reqOrderList];
    [self.tableView.footer endRefreshing];
}


-(void)reqDeleteOrder : (MyOrderModel *)data
{
    [MBProgressHUD showMessage:@"正在加载" toView:self.view];
    
    [self.netTool GetDataFromServerWithPostMethodandInterfaceName:DleteMyOrderInterface andParameter:@[@{@"order_id":data.order_id}] tag:9];
}

#pragma mark tableView datasource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if(self.isPayedStatus)
    {
        return self.order_Pay.count;
    }
    return self.order_NotPay.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
//    CGFloat baseHeight = 106 - 34;
//    MyOrderModel *data = nil;
//    if(self.isPayedStatus)
//    {
//        data = [self.order_Pay objectAtIndex:indexPath.row];
//    }
//    else
//    {
//        data = [self.order_NotPay objectAtIndex:indexPath.row];
//    }
//    if(data == nil)
//        return 106;
//    CGFloat width = [UIScreen mainScreen].bounds.size.width - 81 - 120;
//    CGFloat maxHeight = 999;
//    NSString *str = data.introduction;
//    UIFont *font = [UIFont fontWithName:@"Hiragino Sans GB" size:10];
//    CGSize maxSize = CGSizeMake(width, maxHeight);
//    CGSize textSize = [CommFunc sizeWithString:str font:font max:maxSize];
//    if(textSize.height > 41)
//    {
//        baseHeight = baseHeight + textSize.height;
//    }else
//    {
//        baseHeight = 106;
//    }
//    return baseHeight;
    
    return 106;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(self.isPayedStatus)
    {
        if ([self.order_Pay count] == 0)
        {
            UITableViewCell *cell = [[UITableViewCell alloc]init];
            return cell;
        }
    }
    else
    {
        if ([self.order_NotPay count] == 0)
        {
            UITableViewCell *cell = [[UITableViewCell alloc]init];
            return cell;
        }
    }
    
    MyOrderViewCell * cell = nil;
    NSString * identify = @"MyOrderTableViewCell";
    cell = [self.tableView dequeueReusableCellWithIdentifier:identify];
    if(cell == nil)
    {
        cell = [MyOrderViewCell loadFromNib];
    }
    [self configCell:indexPath.row cell:cell];
    return cell;
}

-(UITableViewCellEditingStyle)tableView:(UITableView*)tableView  editingStyleForRowAtIndexPath:(NSIndexPath*)indexPath
{
    return UITableViewCellEditingStyleDelete;
}

-(void)tableView:(UITableView*)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath*)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete)
    {
        NSInteger row = [indexPath row];
        
        //[self.data removeObjectAtIndex:row];
        MyOrderModel* data = nil;
        if(self.isPayedStatus)
        {
            data = [self.order_Pay objectAtIndex:row];
            [self.order_Pay removeObjectAtIndex:indexPath.row];
        }
        else
        {
            data = [self.order_NotPay objectAtIndex:row];
            [self.order_NotPay removeObjectAtIndex:indexPath.row];
        }
        [self reqDeleteOrder:data];
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
    }
}

-(NSString*)tableView:(UITableView*)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath*)indexpath
{
    return @"取消\n订单";
}


#pragma mark - Table View Delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
    MyOrderModel *data;
    
    if (self.isPayedStatus) //已付款
    {
        data = [self.order_Pay objectAtIndex:indexPath.row];
    }
    else
    {
        data = [self.order_NotPay objectAtIndex:indexPath.row];
    }
    
    if (data.material_id)
    {
        [MBProgressHUD showMessage:@"正在加载" toView:self.view];
        
        QXNetWorkTool *netTools = [[QXNetWorkTool alloc]init];
        netTools.QXNetWorkDelegate = self;
        
        [netTools GetDataFromServerWithPostMethodandInterfaceName:MusicTexBookDetailInterface andParameter:@[@{@"material_id":data.material_id}] tag:10];
    }
}

-(void) configCell : (NSInteger)row cell:(MyOrderViewCell*)mycell
{
    MyOrderModel * data = nil;
    if(self.isPayedStatus)
    {
        if ([self.order_Pay count] == 0)
        {
            return;
        }
        
        data = [self.order_Pay objectAtIndex:row];
        [mycell.btnBuy setEnabled:NO];
        mycell.btnBuy.hidden = YES;
        [mycell.viewBtn setEnabled:YES];
//        mycell.viewBtn.hidden = YES;
        mycell.viewBtn.tag = row;
        [mycell.viewBtn addTarget:self action:@selector(pressViewDetail:) forControlEvents:UIControlEventTouchUpInside];
        [mycell.btnBuy setTag:row];
        [mycell.priceLb setText:@"交易成功"];
        [mycell.orderNameLb setText:data.name];
        [mycell.descLb setText:data.introduction];
        [mycell.priceLb setTextColor:[UIColor blackColor]];
        
        if ([data.major_id isEqualToString:[UserDataSingleton shareInstance].musicBase])
        {
            mycell.image1.image = [UIImage imageNamed:@"img_myOrder_musicBase"];
        }
        else if ([data.major_id isEqualToString:[UserDataSingleton shareInstance].JazzDrum])
        {
            mycell.image1.image = [UIImage imageNamed:@"img_myOrder_jueshigu"];
        }
        else if ([data.major_id isEqualToString:[UserDataSingleton shareInstance].quiTa])
        {
            mycell.image1.image = [UIImage imageNamed:@"Img_myOrder_dianjita"];
        }
        else if ([data.major_id isEqualToString:[UserDataSingleton shareInstance].bass])
        {
            mycell.image1.image = [UIImage imageNamed:@"Img_myOrder_dianbeisi"];
        }
    }
    else
    {
        if ([self.order_NotPay count] == 0)
        {
            return;
        }
        
        data = [self.order_NotPay objectAtIndex:row];
        
        //TODO:wanglei 迷笛那边说把购买按钮暂时屏蔽
        [mycell.btnBuy setEnabled:YES];
        {
            [mycell.btnBuy setEnabled:NO];
            [mycell.btnBuy setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        }
        
//        mycell.btnBuy.hidden = YES;
        [mycell.btnBuy addTarget:self action:@selector(pressBuyBtn:) forControlEvents:UIControlEventTouchUpInside];
        [mycell.btnBuy setTag:row];
        mycell.viewBtn.hidden = YES;
        [mycell.viewBtn setEnabled:NO];
        NSString *text = [NSString stringWithFormat:@"%@%@" , @"价格: " , data.price];
        [mycell.priceLb setText:text];
        [mycell.orderNameLb setText:data.name];
        [mycell.descLb setText:data.introduction];
        [mycell.priceLb setTextColor:[UIColor blackColor]];
        
        if ([data.major_id isEqualToString:[UserDataSingleton shareInstance].musicBase])
        {
            mycell.image1.image = [UIImage imageNamed:@"img_myOrder_musicBase"];
        }
        else if ([data.major_id isEqualToString:[UserDataSingleton shareInstance].JazzDrum])
        {
            mycell.image1.image = [UIImage imageNamed:@"img_myOrder_jueshigu"];
        }
        else if ([data.major_id isEqualToString:[UserDataSingleton shareInstance].quiTa])
        {
            mycell.image1.image = [UIImage imageNamed:@"Img_myOrder_dianjita"];
        }
        else if ([data.major_id isEqualToString:[UserDataSingleton shareInstance].bass])
        {
            mycell.image1.image = [UIImage imageNamed:@"Img_myOrder_dianbeisi"];
        }
    }
}

-(void)pressNotPayedBtn : (UIButton *)sender
{
    if(self.isPayedStatus)
    {
        self.isPayedStatus = NO;
        [self refreshUI];
        
        [self.order_NotPay removeAllObjects];
        self.pageNumNoPaye = 1;
        
        [self reqOrderList];
    }
}

-(void)pressPayedBtn : (UIButton *)sender
{
    if(!self.isPayedStatus)
    {
        self.isPayedStatus = YES;
        [self refreshUI];
        
        [self.order_Pay removeAllObjects];
        self.pageNumPayed = 1;
        
        [self reqOrderList];
    }
}

-(void)pressViewDetail : (UIButton *)sender
{
    QXNetWorkTool *netTools = [[QXNetWorkTool alloc]init];
    netTools.QXNetWorkDelegate = self;
    
    MyOrderModel *data = [self.order_Pay objectAtIndex:sender.tag];
    if (data.material_id)
    {
        [MBProgressHUD showMessage:@"正在加载" toView:self.view];
        
        [netTools GetDataFromServerWithPostMethodandInterfaceName:MusicTexBookDetailInterface andParameter:@[@{@"material_id":data.material_id}] tag:10];
    }
}

-(void)pressBuyBtn : (UIButton *)sender
{
    MyOrderViewCell* buttonCell = (MyOrderViewCell*)[[[sender superview] superview]superview];
    
    if (buttonCell)
    {
        self.selectItemdata = [self.order_NotPay objectAtIndex:sender.tag];
        self.fileUrl = self.selectItemdata.file_url;
        
        MyOrderPayViewControl *obj = [MyOrderPayViewControl create];
        obj.view.backgroundColor = [UIColor clearColor];
        obj.bgImage.alpha = 1;
        UIView *subView = [obj.view viewWithTag:999];
        subView.backgroundColor = [UIColor clearColor];
        
        obj.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
        obj.modalPresentationStyle = UIModalPresentationOverCurrentContext;
        obj.definesPresentationContext = YES;
        obj.myOrderPayViewDeletage = self;
        
        [obj setTitleData:buttonCell.orderNameLb.text];
        [self presentViewController:obj animated:YES completion:nil];
    }
}

-(void)pay:(int)type
{
    if (type == 1) //微信
    {
        UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@"确认支付" message:nil
                                                            delegate:self cancelButtonTitle:@"取消"otherButtonTitles:@"确定",nil];
        
        alertView.tag = 111;
        
        [alertView show];
    }
    else if (type == 2) //支付宝
    {
        UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@"确认支付" message:nil
                                                            delegate:self cancelButtonTitle:@"取消"otherButtonTitles:@"确定",nil];
        
        alertView.tag = 222;
        
        [alertView show];
    }
}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (alertView.tag == 111)
    {
        //微信支付
        if (buttonIndex == 1)
        {
            self.payType = 0;
            [self WXPay];
            return;
        }
    }
    else if (alertView.tag == 222)
    {
        //支付宝支付
        if (buttonIndex == 1)
        {
            self.payType = 1;
            [self Alipay];
            return;
        }
    }
    else if (alertView.tag == 333)
    {
        //没有装微信
        return;
    }
    else if (alertView.tag == 444)
    {
        //查看详情
        if (buttonIndex == 1)
        {
            if (self.fileUrl)
            {
                OperanViewController * ctr = [OperanViewController create];
                [ctr setPDFData:self.fileUrl];
                [self.navigationController pushViewController:ctr animated:YES];
            }
        }
        
        return;
    }
}

-(void) WXPay
{
    if(![WXApi isWXAppInstalled]) // 判断 用户是否安装微信
    {
        UIAlertView *alertView = [[UIAlertView alloc]
                                  initWithTitle:@"您未安装微信，请安装后付款。"
                                  message:nil
                                  delegate:self
                                  cancelButtonTitle:@"确定"
                                  otherButtonTitles:nil, nil];
        
        alertView.tag = 333;
        [alertView show];
        return;
    }
    
    [AccountTool saveOrderId:self.selectItemdata.order_id]; //曲谱教材id
    
    QXNetWorkTool *netTools = [[QXNetWorkTool alloc]init];
    netTools.QXNetWorkDelegate = self;
    
    //微信支付
    int wxPrice = [self.selectItemdata.price floatValue] * 100;
    NSString *strPrice = [[NSString alloc] initWithFormat:@"%d", wxPrice];
    
    //获得prepayid和noncestr
    [netTools GetDataFromServerWithPostMethodandInterfaceName:WXPayGetPrepayIdInterface andParameter:
     @[@{
           @"totalfee":strPrice,
           @"body":self.selectItemdata.name,
           @"outtradeno":self.selectItemdata.orde_code
           }] tag:3];
}

-(void) Alipay
{
    [AccountTool saveOrderId:self.selectItemdata.order_id]; //曲谱教材id
    [AccountTool savePayItem:VPayBuyMusic];
    [AccountTool savePayMusicPopToView:VPayBuyMusicPopToMyOrderView];
    
    //支付宝支付
    [AliPayTool alipayWithOrdercode:@"" orderId:self.selectItemdata.order_id Price:self.selectItemdata.price CityId:@"" Target:self];
}

-(void)GetSuccessResponse:(id)Response andTag:(int)tag
{
    [MBProgressHUD hideHUDForView:self.view];
    
    if(tag == 1)
    {
        for(NSDictionary * dic in Response)
        {
            MyOrderModel *item = [MyOrderModel MyModelWithDic:dic];
            if(self.isPayedStatus)
            {
                [self.order_Pay addObject:item];
//                self.isInitPayOrder = YES;
            }
            else
            {
                [self.order_NotPay addObject:item];
//                self.isInitNotPayOrder = YES;
            }
        }
        [self.tableView reloadData];
        
        //获取未付款信息系详情
        for (MyOrderModel *tmp in self.order_NotPay)
        {
            [MBProgressHUD showMessage:@"正在加载" toView:self.view];
            
            QXNetWorkTool *netTools = [[QXNetWorkTool alloc]init];
            netTools.QXNetWorkDelegate = self;
            
            [netTools GetDataFromServerWithPostMethodandInterfaceName:MusicTexBookDetailInterface andParameter:@[@{@"material_id":tmp.material_id}] tag:2];
        }
    }
    else if (tag == 2)
    {
        [MBProgressHUD hideHUDForView:self.view];
        [MBProgressHUD hideHUDForView:self.view];
        
        //获取资料详情
        MusicTexbookDetailModel *detail;
        for(NSDictionary * dic in Response)
        {
            detail = [MusicTexbookDetailModel MyModelWithDict:dic];
            break;
        }
        
        if (detail)
        {
            for (MyOrderModel *i in self.order_NotPay)
            {
                if ([i.material_id isEqualToString:detail.id])
                {
                    i.file_url = detail.file_url;
                    break;
                }
            }
        }
    }
    else if(tag == 3)
    {
        for(NSDictionary * dic in Response)
        {
            WXPrePayIdModel * item = [WXPrePayIdModel WXPrePayIdModelWithDict:dic];
            
            NSString *prepayid = item.prepayid;
            NSString *noncestr = item.noncestr;
            
            int wxPrice = [self.selectItemdata.price floatValue] * 100;
            NSString *strPrice = [[NSString alloc] initWithFormat:@"%d", wxPrice];
            
            [AccountTool savePayItem:VPayBuyMusic];
            [AccountTool savePayMusicPopToView:VPayBuyMusicPopToMyOrderView];
            
            //微信支付
            [WeChatPayTool WeChatWithOrdercode:@""
                                      prepayid:prepayid
                                       orderId:self.selectItemdata.order_id
                                         Price:strPrice
                                        CityId:@""
                                      noncestr:noncestr
                                        Target:self];
            break;
        }
    }
    else if(tag == 9)
    {
        UserDataSingleton *userdata = [UserDataSingleton shareInstance];
        userdata.isOrderChange = YES;
    }
    else if (tag == 10)
    {
        for(NSDictionary * dic in Response)
        {
            MusicTexbookDetailModel * item = [MusicTexbookDetailModel MyModelWithDict:dic];

            NSString *buy = @"0";
            if (self.isPayedStatus)
            {
                buy = @"1";
            }
            
            NSString * itemId = item.id;
            
            NSString *type = item.type;
            BOOL isMusicPage = YES;
            if([type isEqualToString:@"2"])
            {
                isMusicPage = NO;
            }
            BuyMusicDetailViewViewController *ctr = [BuyMusicDetailViewViewController create];
            
            [ctr setData:isMusicPage data:itemId Buy:buy];
            
            [self.navigationController pushViewController:ctr animated:YES];
            
            [AccountTool savePayMusicPopToView:VPayBuyMusicPopToMyOrderView];
            
            break;
        }
    }
}

-(void)GetFailResponse:(id)Response andTag:(int)tag
{
    switch (tag)
    {
        case 1:
        case 2:
        case 9:
        {
            [MBProgressHUD hideHUDForView:self.view];
            [MBProgressHUD showError:(NSString *)Response toView:self.view];
            break;
        }
        case 6666:
        case 7777:
        case 8888:
            [MBProgressHUD hideHUD];
            //            [MBProgressHUD showSuccess:(NSString*)message];
            break;
        default:
        {
//            [MBProgressHUD hideHUDForView:self.view];
//            [MBProgressHUD showError:(NSString*)Response toView:self.view];
            [MBProgressHUD showError:(NSString*)Response];
            break;
        }
    }
}

-(void)GetSuccessMessage:(id)message andTag:(int)tag
{
    switch (tag)
    {
        case 1:
        case 9:
        {
            [MBProgressHUD showSuccess:(NSString*)message toView:self.view];
            break;
        }
        case 6666:
        {
            [MBProgressHUD hideHUD];
            
            //记录成功
            if ([[AccountTool takePayResult] isEqualToString:VPaySuccess])
            {
                if (self.fileUrl)
                {
                    UIAlertView * alertView = [[UIAlertView alloc]
                                               initWithTitle:@"支付成功"
                                               message:nil
                                               delegate:self
                                               cancelButtonTitle:@"取消"
                                               otherButtonTitles:@"查看",nil];
                    alertView.tag = 444;
                    [alertView show];
                    
                    [self refreshOrderNotPayList];
                }
            }
            break;
        }
        case 7777:
        case 8888:
        {
            [MBProgressHUD hideHUD];
            //            [MBProgressHUD showSuccess:(NSString*)message];
            break;
        }
    }
}

-(void)refreshOrderNotPayList
{
    [self.order_NotPay removeAllObjects];
    
    self.pageNumNoPaye = 1;
    
    [self reqOrderList];
}



@end





































